qx.Class.define("lastfmbackup.test.mock.RecentTracksModel", {
  
  extend : qx.core.Object,
  
  properties : {
    
    username : {
      check        : "String",
      deferredInit : true
    },
    
    blockSize : {
      check : "Number",
      init  : 2
    },
    
    fail : {
      check : "Boolean",
      init  : false
    },
    
    delay : {
      check : "Number",
      init  : 100
    }
    
  },
  
  events : {

    load : "qx.event.type.Data",
    
    fail : "qx.event.type.Data"
    
  },
  
  statics : {
    
    data : [
      [1359209542, "Ithica 27 ϕ 9", "Mogwai", "Ten Rapid",
        "fc526a84-081b-4491-b598-4c93ec14b0f5", "cee3f961-4197-483b-a3ad-73242a97eb4a", null],
      [1359132220, "Artifact", "Balmorhea", "Stranger", "11f72b3e-129a-4d77-a338-d68bd2221dd9",
        "1507b368-e660-4c15-af94-3f5603561045", "46ad1d93-0492-45fd-9b48-c385d50b6201"],
      [1359109862, "Canvas", "Soen", "Cognitive", "40ad5ea4-4d0a-4765-afa0-5ce9c2adc4c1",
        "7a42f70d-7c01-46d2-bd88-738967a631f0", "f49a475d-215f-4f63-a515-3bc3aab25874"],
      [1358959513, "The Dreaming", "Jurojin", "The Living Measure Of Time",
        "589006c8-b6b2-460c-aa2c-bcd48849307f", "bcde4cf4-8f13-4e55-b867-c9eeeab77015", 
        "3616c7ae-3a27-44c6-8499-0eed4f91cfe0"],
      [1358501427, "Gone in Bloom and Bough", "Caspian", "Waking Season", 
        "8994b9e4-3da2-4f73-9be6-d9513c156477", "f8a5d80c-a6b7-414c-9482-c5d710171622", 
        "f157e1be-c650-47d7-9c81-c1f8c0e317f7"],
      [1358333559, "Häxprocess", "Opeth", "Heritage", "5092d91e-f350-4af4-bf69-f60c5c9e417e",
        "c14b4180-dc87-481e-b17a-64e4150f90f6", "40b71a83-6aca-4cdb-84b1-fa1b60ea4457"],
      [1357835873, "Vicarious", "Tool", "10,000 Days", "01487ac6-8d3c-4d67-a31b-ae59cc752e64",
        "22c94bce-544f-49ba-afdc-026beac4fd3e", "25e3c73d-0ad1-3da5-bc6f-e3105754a597"]
    ]
    
  },
  
  members : {
    
    count : function()
    {
      var length    = this.constructor.data.length;
      var blockSize = this.getBlockSize();
      qx.event.Timer.once(function()
      {
        if(this.getFail())
        {
          this.fireDataEvent("fail", {"type" : "count"});  
        }
        else
        {
          this.fireDataEvent("load", {
            "type" : "count",
            "data" : {
              "user"       : this.getUsername(),
              "page"       : 1,
              "perPage"    : this.getBlockSize(),
              "totalPages" : Math.floor(length / blockSize) + (length % blockSize ? 1 : 0),
              "total"      : length
            }
          });
        }
      }, this, this.getDelay());
    },
    
    page : function(page)
    {
      var data = this.constructor.data;
      qx.event.Timer.once(function()
      {
        if(this.getFail())
        {
          this.fireDataEvent("fail", {"type" : "page"});
        }
        else
        {
          var slice = data.slice((page - 1) * this.getBlockSize(), page * this.getBlockSize());
          this.fireDataEvent("load", {
            "type" : "page",
            "data" : slice.map(lastfmbackup.model.Storage.convertToMap)
          });
        }
      }, this, this.getDelay());
    }
    
  }
  
});